function [pos, pairs] = optimal_cons(pix, dist, init,width,height)
%pix 2*n n:wifipix number
%dist 1*n
%init 2*1
%pos 2*1->init
%pairs n*n
n = size(dist, 2);
pairs = zeros(n);
options = optimoptions('fmincon', 'MaxIter', 100); 
[~, param] = evalc('fmincon(@(t)(cost_cons(t, pix, dist)),init,[],[],[],[],[0,0],[width,height],[],options)');
%param = fmincon(@(t)(cost_cons(t, pix, dist)),init,[],[],[],[],[0,0],[width,height],[],options);
pos = param(1:2);

for i = 1 : n - 1
    for j = i + 1 : n
        d1 = norm(pos - pix(:, i));
        d2 = norm(pos - pix(:, j));
        if (dist(i) - dist(j)) * (d1 - d2) >= 0
            pairs(i, j) = 1;
            pairs(j, i) = 1;
        end
    end
end

